#pragma once

#include "CeBrainCommon.h"
#include "Nervus.h"

class CTrainingCase
{
public:
	CTrainingCase(void);
	CTrainingCase( EOBJTYPE tEnvRoundMe[ ALL_DIRECTION_COUNT ] );
	~CTrainingCase(void);

	Complex GetSignalForNervus( int nNervusIndex );
	RESULT_JUDGMENT CompareNervusOutputSignal( void );

	void InitOutSignal( void )
	{
		for( int i=0; i<OUTPUT_SIGNAL_COUNT; i++ )
			m_nOutputSignal[i] = 0;
	};

	void TransmitSignal( void )
	{
		for( int j=0; j<INPUT_SIGNAL_COUNT; j++ )
		{
			m_pinInput[j].SetSignal( GetSignalForNervus( j ) );
			//TRACE( "-->%d:%d", j, m_pinInput[j].ReadCurrentSignal());
			m_pinInput[j].TransmitSignal();
		}
	};

	void GetOutputSignal( void )
	{
		for( int k=0; k<OUTPUT_SIGNAL_COUNT; k++ )
		{
			//m_nOutputSignal[i] += m_pinOutput[i].GetSignal();
			if( m_pinOutput[k].GetSignal().Model() > NERVUS_MODEL_LEVEL )
				m_nOutputSignal[k] ++;
			//TRACE( "[%d: %lf]\n", k, m_pinOutput[k].GetSignal().Model());
		}
	};

	void ConnectInputOutput( CNervusMap *pNervusMap )
	{
		for( int i=0; i<OUTPUT_SIGNAL_COUNT; i++ )
			pNervusMap->GetNervus( i, NERVUS_MAP_DEPTH-1 )->Connect( 0, &m_pinOutput[i] );

		for( int j=0; j<INPUT_SIGNAL_COUNT; j++ )
			m_pinInput[j].Connect( pNervusMap->GetNervus( j, 0 )->FindEmptyInputAntennna() );
	}

private:
	Complex m_nInputSignalSequence[ INPUT_SIGNAL_COUNT ][ ALL_DIRECTION_COUNT ];
	EOBJTYPE m_tEnvRoundMe[ ALL_DIRECTION_COUNT ];
	int m_nCurrentSignal[INPUT_SIGNAL_COUNT];
	CNervusAntenna m_pinInput[ INPUT_SIGNAL_COUNT ];
	CNervusAntenna m_pinOutput[ OUTPUT_SIGNAL_COUNT ];
	int m_nOutputSignal[ OUTPUT_SIGNAL_COUNT ];
};

